﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Retirement_topUpPremium : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int requestId = Convert.ToInt32(this.Request.QueryString["requestId"]);
            Requests req = Requests.getRequest2(requestId);
            this.lb_topUpAmount.Text = req.totalAmount.ToString("###,###.00");
            

            if ("Y".Equals(req.metRepresentative))
            {
                this.cb_metRepresentative.Checked = true;
                this.cb_didNotMetRepresentative.Checked = false;
            }
            else
            {
                this.cb_metRepresentative.Checked = false;
                this.cb_didNotMetRepresentative.Checked = true;
            }

            int i = 1;
            foreach (RequestsFund reqFund in req.requestFunds)
            {
                if (i == 1)
                {
                    ddl_topUpFund1.SelectedValue = reqFund.code;
                    tb_topUpFundPercentage1.Text = (reqFund.percentage * 100).ToString("#.##");

                }
                else if (i == 2)
                {
                    ddl_topUpFund2.SelectedValue = reqFund.code;
                    tb_topUpFundPercentage2.Text = (reqFund.percentage * 100).ToString("#.##");
                }
                else if (i == 3)
                {
                    ddl_topUpFund3.SelectedValue = reqFund.code;
                    tb_topUpFundPercentage3.Text = (reqFund.percentage * 100).ToString("#.##");
                }
                else if (i == 4)
                {
                    ddl_topUpFund4.SelectedValue = reqFund.code;
                    tb_topUpFundPercentage4.Text = (reqFund.percentage * 100).ToString("#.##");

                }
                else if (i == 5)
                {
                    ddl_topUpFund5.SelectedValue = reqFund.code;
                    tb_topUpFundPercentage5.Text = (reqFund.percentage * 100).ToString("#.##");
                }
                i++;
            }

        }
    }
    protected void btn_approve_Click(object sender, ImageClickEventArgs e)
    {
        Dictionary<string, string> targetPercentage = new Dictionary<string, string>();
        if (!Util.IsBlank(ddl_topUpFund1.SelectedValue))
        {
            targetPercentage.Add(ddl_topUpFund1.SelectedValue, this.tb_topUpFundPercentage1.Text);
        }

        if (!Util.IsBlank(ddl_topUpFund2.SelectedValue))
        {
            targetPercentage.Add(ddl_topUpFund2.SelectedValue, this.tb_topUpFundPercentage2.Text);
        }

        if (!Util.IsBlank(ddl_topUpFund3.SelectedValue))
        {
            targetPercentage.Add(ddl_topUpFund3.SelectedValue, this.tb_topUpFundPercentage3.Text);
        }

        if (!Util.IsBlank(ddl_topUpFund4.SelectedValue))
        {
            targetPercentage.Add(ddl_topUpFund4.SelectedValue, this.tb_topUpFundPercentage4.Text);
        }

        if (!Util.IsBlank(ddl_topUpFund5.SelectedValue))
        {
            targetPercentage.Add(ddl_topUpFund5.SelectedValue, this.tb_topUpFundPercentage5.Text);
        }


        PolicyRules policyRules = new PolicyRules();

        int requestId = Convert.ToInt32(this.Request.QueryString["requestId"]);
        Requests req = Requests.getRequest2(requestId);

        policyRules.topUp(req.policyNo, Convert.ToDecimal(this.lb_topUpAmount.Text), targetPercentage);
        req.approve(req.requestId);
        this.Response.Redirect("./manageClients.aspx");
    }
    protected void btn_reject_Click(object sender, ImageClickEventArgs e)
    {
        int requestId = Convert.ToInt32(this.Request.QueryString["requestId"]);
        Requests req = new Requests();
        req.reject(req.requestId,this.tb_rejectReason.Text);
    }
}